package com.example.demo03_mvm.repos;

import androidx.lifecycle.MutableLiveData;

import com.example.demo03_mvm.db.DBInstance;
import com.example.demo03_mvm.db.Goods;
import com.example.demo03_mvm.model.BaseModel;
import com.example.demo03_mvm.model.GoodDetailEntity;
import com.example.demo03_mvm.model.GoodsEntity;
import com.example.demo03_mvm.model.GoodsTypeEntity;

import io.reactivex.functions.Action;
import io.reactivex.functions.Consumer;
import retrofit2.http.Query;

public class GoodsTypeRepos extends BaseModel {

    public MutableLiveData<GoodsTypeEntity> getTypes(){
        return getData(getApi().getTypes(),new MutableLiveData<>());
    }

    public MutableLiveData<GoodsTypeEntity> getGoods(int tid){
        return getData(getApi().getGoods(tid),new MutableLiveData<>());
    }

    public MutableLiveData<GoodsEntity> getGoodList(int currentPage,int pageSize){
        return getData(getApi().getGoodList(currentPage, pageSize),new MutableLiveData<>());
    }

    public MutableLiveData<GoodDetailEntity> getGoodDetail(int gid){
        return getData(getApi().getGoodDetail(gid),new MutableLiveData<>());
    }

    public void insert(Goods goods, Action action){
        update(DBInstance.getGoodsDataBase().getGoodsDao().insert(goods),action);
    }

    public void select(Consumer consumer){
        select(DBInstance.getGoodsDataBase().getGoodsDao().getGoodsList(),consumer);
    }

    public void getGoodsByid(int gid,Consumer consumer){
        select(DBInstance.getGoodsDataBase().getGoodsDao().getGoods(gid),consumer);
    }



}
